'''此文件是把一个礼让行人的四合一图片分开裁剪成四张'''
import os
import shutil
import cv2
from tqdm import tqdm
from PIL import Image
Image.LOAD_TRUNCATED_IMAGES = True
path = '/home/xys/paper/ReID/data_lirangperson/'
save_path = '/home/xys/paper/ReID/data_vehicle_test/bounding_box_test/'

file_names = os.listdir(path)

for file in tqdm(file_names):
    file1_name = os.path.basename(file)
    file1_name = file1_name.split('.')[0]
    image = Image.open(os.path.join(path + file))
    try:
        img = image.convert('RGB')
    except OSError:
        print(os.path.join(path + file))
        continue
    w = img.size[0]
    h = img.size[1]
    img_1 = img.crop([0, 0, w / 2, h / 2])  # 获取左上1/4的图片
    img_1.save(save_path + file1_name + '-1' + '.jpg')  # 保存图片并命名
    img_2 = img.crop([w / 2, 0, w, h / 2])  # 获得右上1/4的图片
    img_2.save(save_path + file1_name + '-2' + '.jpg')
    img_3 = img.crop([0, h / 2, w / 2, h])  # 获取左下1/4的图片
    img_3.save(save_path + file1_name + '-3' + '.jpg')
    img_4 = img.crop([w / 2, h / 2, w, h])  # 获取右下1/4的图片
    img_4.save(save_path + file1_name + '-4' + '.jpg')
    # shutil.copy(os.path.join(path + file), os.path.join(save_path + file))

